<?php
    $url = new Url();
?>

<script type="text/javascript">

    $(document).ready(function() {

        $('#somo').addClass('active');

        loadChat("<?=$url->createUrl('home/chat')?>");

        $('.From').keypress(function(e){
            if(e.keyCode == 13 && !e.shiftKey){
                $(this).trigger("enterKey");
            } 
        });

        $('textarea').bind("enterKey",function(e){
            var messenger = $('.From').val();
            var url = "<?=$url->createUrl('home/chat'); ?>";
            $.ajax({
                type: "GET",
                url: url,
                global: false,
                data: {
                    messenger: messenger,
                },
                success: function(msg){  
                    if(msg==1){
                        alert('Bạn phải đăng nhập để tán gẫu');
                    }
                    if(msg==0){
                        alert('Bạn phải chưa nhập nội dung');
                    }
                    else
                    {
                        $("#CHAT").html(msg);
                        $('.From').val('');
                    }

                }
            });
        });

        $("#<?php echo $page?>").removeClass('numbertrang');
        $("#<?php echo $page?>").addClass('numbertrang_1');
    });

    function boxSearch(page){
        var search = $('.boxsearchSM').val();
        var url = "<?=$url->createUrl('tienich/search');?>";
        $.ajax({
            type:"POST",
            url: url,
            data: {
                search: search,
                page: page,
            },
            success:function(msg){
                $('.Main').html(msg);
            }
        });
    }

    function boxLetter(a){
        //alert('test');
        var url = "<?=$url->createUrl('tienich/search')?>";
        $.ajax({
            type: "POST",
            url: url,
            data: {
                search: a,
            },
            success:function(msg){
                $('.Main').html(msg);
            }
        });
    }

    function pageSearch(a,b){
        //alert('test');
        var url = "<?=$url->createUrl('tienich/search')?>";
        $.ajax({
            type: "POST",
            url: url,
            data: {
                page: a,
                search: b,
            },
            success:function(msg){
                $('.Main').html(msg);
            }
        });
    }

    function loadChat(url){
        var scroll = $('.boxCHAT').scrollTop();
        //alert(scroll);
        $.ajax({
            type: "POST",
            url: url,
            global: false,
            data:{
                
            },
            success:function(msg){
                $("#CHAT").html(msg);
            }
        });
    }

    function messenger(){
        var messenger = $('.From').val();
        var url = "<?=$url->createUrl('home/chat'); ?>";
        $.ajax({
            type: "GET",
            url: url,
            data: {
                messenger: messenger,
            },
            success: function(msg){
                if(msg==1){
                    alert('Bạn phải đăng nhập để tán gẫu');
                }
                if(msg==0){
                    alert('Bạn phải chưa nhập nội dung');
                }
                else
                {
                    $("#CHAT").html(msg);
                    $('.From').val('');
                }
            }
        });
    };

</script>

<div class="leftMain">
    <div class="titleCHAT">
        <h1>Sổ Mơ</h1>
    </div>
    <div class="SM">
        <div class="searchSM">
            <input name="a" type="text" placeholder="Nhập từ khóa" size="5" maxlength="100" class="boxsearchSM" />
            <a href="javascript:void(0);" onclick="boxSearch(1);" class="buttonsearchSMS">Tìm Kiếm</a>
        </div>
        <div class="searchLetters">
            <div class="titleLetters red">Tìm theo chữ cái</div>
            <div style="margin-bottom:30px;">
                <a href="javascript:void(0);" onclick="boxLetter('a')" class="boxLetters">A</a>
                <a href="javascript:void(0);" onclick="boxLetter('b')" class="boxLetters">B</a>
                <a href="javascript:void(0);" onclick="boxLetter('c')" class="boxLetters">C</a>
                <a href="javascript:void(0);" onclick="boxLetter('d')" class="boxLetters">D</a>
                <a href="javascript:void(0);" onclick="boxLetter('e')" class="boxLetters">E</a>
                <a href="javascript:void(0);" onclick="boxLetter('f')" class="boxLetters">F</a>
                <a href="javascript:void(0);" onclick="boxLetter('g')" class="boxLetters">G</a>
                <a href="javascript:void(0);" onclick="boxLetter('h')" class="boxLetters">H</a>
                <a href="javascript:void(0);" onclick="boxLetter('i')" class="boxLetters">I</a>
                <a href="javascript:void(0);" onclick="boxLetter('k')" class="boxLetters">K</a>
                <a href="javascript:void(0);" onclick="boxLetter('l')" class="boxLetters">L</a>
                <a href="javascript:void(0);" onclick="boxLetter('m')" class="boxLetters">M</a>  
                <a href="javascript:void(0);" onclick="boxLetter('n')" class="boxLetters">N</a>
            </div>
            <div style="margin-bottom:30px;">
                <a href="javascript:void(0);" onclick="boxLetter('o')" class="boxLetters">O</a>
                <a href="javascript:void(0);" onclick="boxLetter('p')" class="boxLetters">P</a>
                <a href="javascript:void(0);" onclick="boxLetter('q')" class="boxLetters">Q</a>
                <a href="javascript:void(0);" onclick="boxLetter('r')" class="boxLetters">R</a>
                <a href="javascript:void(0);" onclick="boxLetter('s')" class="boxLetters">S</a>
                <a href="javascript:void(0);" onclick="boxLetter('t')" class="boxLetters">T</a>
                <a href="javascript:void(0);" onclick="boxLetter('u')" class="boxLetters">U</a>
                <a href="javascript:void(0);" onclick="boxLetter('v')" class="boxLetters">V</a>
                <a href="javascript:void(0);" onclick="boxLetter('x')" class="boxLetters">X</a>
                <a href="javascript:void(0);" onclick="boxLetter('y')" class="boxLetters">Y</a>
            </div>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr class="bg_cam">
                <td class="SM_1"><p>STT</p></td>
                <td class="SM_2"><p>Bạn mơ thấy gì</p></td>
                <td class="SM_2"><p>Cặp số tương ứng</p></td>
            </tr>
        </table>
        <table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#e6e6e6">

            <?php for($i=0;$i<count($data);$i++){?>
                <tr class="bg_white">
                    <td class="SM_1"><?php echo $i+1;?></td>
                    <td class="SM_2"><strong class="red"><?php echo $data[$i]['title_long'];?></strong></td>
                    <td class="SM_2"><strong class="cam"><?php echo $data[$i]['result'];?></strong></td>
                </tr>
                <?php }?>


        </table>
        <div class="trangSM">
            Trang
            <?php
                if(isset($search))
                {
                    $pageing = Common::pageSearch($total_page,$page,$search);
                    echo $pageing;
                }
                else
                {
                    $pageing = Common::pageSomo($total_page,$page);
                    echo $pageing;
                }
            ?>
        </div>
        <div class="sms_LOTO">
            <?php echo Yii::app()->params['static_sms'];?>
        </div>
        <div class="MXH">
            <div id="fb-root" style="float: right;"></div>
            <script>(function(d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) return;
                js = d.createElement(s); js.id = id;
                js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=670383849682676&version=v2.0";
                fjs.parentNode.insertBefore(js, fjs);
                }(document, 'script', 'facebook-jssdk'));
            </script>
            <div class="fb-like" data-href="http://10h.vn/" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
        </div>
    </div>

    <div class="CHAT">
            
        <div class="titleCHAT">
            Tán Gẫu
        </div>
        
        <div class="CHATarea">
            <textarea name="CHAT" placeholder="Nhập nội dung chat" cols="50" rows="1" class="From"></textarea>
        </div>
        <div style="padding:15px 20px 20px 0; text-align:right;">
            <a href="javascript:void(0);" id="emotion"><img src="<?php echo Yii::app()->params['static_url'];?>images/xo-so-10h-icon-yahoo.png" width="22" height="22" style="padding-right:10px;"></a>
            <a href="javascript:void(0);" onclick="loadChat('<?=$url->createUrl('home/chat')?>');"><img src="<?php echo Yii::app()->params['static_url'];?>images/Refresh.png" width="22" height="22" style="padding-right:10px;" /></a>
            <input type="button" onclick="messenger();" class="button_KQ" value="Gửi">
        </div>

        <div class="boxCHAT" id="CHAT"></div>
        
        <?php $this->renderPartial('boxemotion');?>
        
    </div>

</div>
<div class="rightMain">

    <div class="Box" id="boxtienich">
        <?php $this->renderPartial('boxtienich');?>
    </div>

    <div class="Box" id="boxketqua">
        <?php
            $this->renderPartial('boxketqua');
        ?>
    </div>

    <div class="Box" id="boxthongke">
        <?php $this->renderPartial('boxthongke');?>
    </div>

    </div>
    <div class="both"></div>
